package com.eascs.web.p2p.loginAction;

import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.p2p.common.service.InvestorService;
import com.eascs.web.captcha.controller.CaptchaBuilder;
import com.eascs.web.captcha.patchca.service.Captcha;
import com.eascs.web.context.ResponseContext;
import com.eascs.web.p2p.common.BaseMasterViewController;

@RequestMapping("/admin")
@Controller
public class LoginController extends BaseMasterViewController {
	private final Logger logger = LoggerFactory.getLogger(LoginController.class);
	private CaptchaBuilder captchaBuilder = new CaptchaBuilder();
	@Reference
	InvestorService investorService;

	@RequestMapping(value = "/index")
	public String index() {
		return "/admin/login";
	}
	


	@RequestMapping(value = "/captcha/yzm")
	public void buidCaptchaImage(HttpServletResponse resp) throws IOException {
		ResponseContext.setContentType(MediaType.IMAGE_PNG_VALUE);
		ResponseContext.setDateHeader("Expries", 0);
		ResponseContext.setHeader("Pragma", "no-cache");
		Captcha captcha = captchaBuilder.buildCaptcha();
		CaptchaBuilder.SESSION_CAPTCHA.setValue(captcha.getChallenge());
		try {
			ImageIO.write(captcha.getImage(), "png", ResponseContext.getOutputStream());
		} catch (IOException e) {

		}
	}
	
	
}
